<!-- 培养方案执行详情 -->
<template>
  <div class="assessment-edit-plan-container">
    <div class="my-form-container" style="width:95%;height: 100%">
      <el-row class="my-form-item">
        <el-col :span="12">
          <div class="my-form-item-label">名称</div>
          <div class="my-form-item-value">{{ initList.mc }}</div>
        </el-col>
        <el-col :span="12">
          <div class="my-form-item-label">版本</div>
          <div class="my-form-item-value">{{ initList.bb }}</div>
        </el-col>
      </el-row>
      <el-row class="my-form-item">
        <el-col :span="12">
          <div class="my-form-item-label">适用专业</div>
          <div class="my-form-item-value">{{ initList.syzy }}</div>
        </el-col>
        <el-col :span="12">
          <div class="my-form-item-label">课程分类</div>
          <div class="my-form-item-value">{{ initList.pyfafl }}</div>
        </el-col>
      </el-row>
      <el-row class="my-form-item">
        <el-col :span="24">
          <div class="my-form-item-label">额定总学分</div>
          <div class="my-form-item-value">{{ initList.edzxf }}</div>
        </el-col>
      </el-row>
      <el-row class="my-form-item">
        <el-col :span="12">
          <div class="my-form-item-label">必修课额定学分</div>
          <div class="my-form-item-value">{{ initList.bxkedxf }}</div>
        </el-col>
        <el-col :span="12">
          <div class="my-form-item-label">选修课额定学分</div>
          <div class="my-form-item-value">{{ initList.xxkedxf }}</div>
        </el-col>
      </el-row>
      <el-row class="my-form-item">
        <el-col :span="12">
          <div class="my-form-item-label">自修课额定学分</div>
          <div class="my-form-item-value">{{ initList.zxkedxf }}</div>
        </el-col>
        <el-col :span="12">
          <div class="my-form-item-label">讲座课额定学分</div>
          <div class="my-form-item-value">{{ initList.jzkedxf }}</div>
        </el-col>
      </el-row>
      <el-row class="my-form-item">
        <el-col :span="12">
          <div class="my-form-item-label">实践教学额定学分</div>
          <div class="my-form-item-value">{{ initList.sjjxedxf }}</div>
        </el-col>
        <el-col :span="12">
          <div class="my-form-item-label">教育训练额定学分</div>
          <div class="my-form-item-value">{{ initList.jyxledxf }}</div>
        </el-col>
      </el-row>
      <el-row class="my-form-item">
        <el-col :span="24" style="display: flex; align-items: center">
          <div class="my-form-item-label">附件</div>
          <div class="my-form-item-value">{{ initList.fj }}</div>
        </el-col>
      </el-row>
      <el-row class="my-form-item" style="height: 100px">
        <el-col :span="24">
          <div class="my-form-item-label">备注</div>
          <div class="my-form-item-value">{{ initList.sm }}</div>
        </el-col>
      </el-row>
    </div>
    <!-- 下表格 -->
    <div style="width:95%;margin:0 auto">
      <template>
        <div class="my-form-boder" style="height: 100%">
          <span
            style="
              font-weight: bold;
              line-height: 45px;
              color: #004ca7;
            "
            >本（专）科专业人才培养方案</span
          >
          <div class="my-border-container" style="margin-top: 20px">
            <el-tree
              ref="treeData"
              :data="setTreedata"
              :props="defaultProps"
              default-expand-all="true"
              :current-node-key="currentLivingId"
              @node-click="handleNodeClick"
              node-key="id"
            ></el-tree>
            <div style="color:#004CA7;font-weight:600;margin: 15px 40px">
              额定学分：<span class="middInfo">{{edxf}}</span>
              额定学时：<span class="middInfo">{{edxs}}</span>
              已设定课程学分：必修：<span style="margin-right:80px">{{xuefen}}</span>选修：<span>{{xxxuefen}}</span>
            </div>
            <el-table
              :data="tableData"
              border
              style="width: 95%;margin:30px auto"
              class="table-data"
              row-class-name="row-class"
              cell-class-name="cell-class"
              header-row-class-name="header-row-class"
              header-cell-class-name="header-cell-class"
            >
              >
              <el-table-column
                prop="kcph"
                align="center"
                label="课程编号(名称)"
              >
                <template slot-scope="scope">
                  {{ scope.row.kcph }}【{{ scope.row.coursename }}】
                </template>
              </el-table-column>
              <el-table-column prop="xuefen" align="center" label="学分">
              </el-table-column>
              <el-table-column prop="xxlx" align="center" label="修习类型">
              </el-table-column>
              <el-table-column prop="khfs" align="center" label="考核方式">
              </el-table-column>
              <el-table-column prop="xnxq" align="center" label="学年（学期）">
                <template slot-scope="scope">
                  {{ scope.row.xnxq }}【{{ scope.row.season }}】
                </template>
              </el-table-column>
              <el-table-column prop="xuehour" align="center" label="学时（门数）">
                <template slot-scope="scope">
                  {{ scope.row.xueshi }}【{{ scope.row.menshu }}】
                </template>
              </el-table-column>
              <el-table-column prop="qtkkkxq" align="center" label="其他可开课学期"></el-table-column>
            </el-table>
            <el-table
              :data="yearTable"
              border
              style="width: 95%;margin: 20px auto"
              class="table-data"
              row-class-name="row-class"
              cell-class-name="cell-class"
              header-row-class-name="header-row-class"
              header-cell-class-name="header-cell-class"
              :span-method="objectSpanMethod"
            >
              <el-table-column prop="" align="center" label="">
                <template slot-scope="scope">
                  总计：学时（门数）
                </template>
              </el-table-column>
              <!-- <el-table-column prop="year" align="center" width="120" v-for="(item,index) in xnList"
                  :key="index"
                  :label="item"
                  :value="item">
              </el-table-column> -->
              <el-table-column prop="year" align="center" label="学年">
              </el-table-column>
              <el-table-column prop="season" align="center" label="学期">
              </el-table-column>
              <el-table-column prop="classHours" align="center" label="总学时">
                <template slot-scope="scope">
                  {{ scope.row.classHours }}【{{ scope.row.numbers }}】
                </template>
              </el-table-column>
            </el-table>
          </div>
          <div>
            <!-- <el-tree
              :data="data"
              :props="defaultProps"
              @node-click="handleNodeClick"
            ></el-tree> -->
            <!-- <el-table
              :data="tableData"
              border
              style="width: 100%"
              class="table-data"
              row-class-name="row-class"
              cell-class-name="cell-class"
              header-row-class-name="header-row-class"
              header-cell-class-name="header-cell-class"
            >
              <el-table-column prop="sc" label="总计:学时(门数)" align="center">
                <template slot-scope="scope">
                  <button
                    style="
                      width: 54px;
                      height: 27px;
                      background: #ffefef;
                      border: 1px solid #fa5339;
                      border-radius: 4px;
                      font-size: 14px;
                      color: #ff3819;
                    "
                  >
                    删除
                  </button>
                </template>
              </el-table-column>
              <el-table-column prop="dyxn" align="center" label=" 第一学年">
                <template slot-scope="scope">
                  <el-table
                    :data="tableData2"
                    border
                    style="width: 100%"
                    class="table-data"
                    row-class-name="row-class"
                    cell-class-name="cell-class"
                    header-row-class-name="header-row-class"
                    header-cell-class-name="header-cell-class"
                  >
                    <el-table-column prop="qiu" align="center" label=" 秋">
                      <template slot-scope="scope">
                            <div>{{scope.row.qiu}}12323</div>
                          </template>
                    </el-table-column>
                    <el-table-column prop="chun" align="center" label=" 春">
                    </el-table-column>
                  </el-table>
                </template>
              </el-table-column>
              <el-table-column prop="dyxn" align="center" label=" 第二学年">
                <template slot-scope="scope">
                  <el-table
                    :data="tableData2"
                    border
                    style="width: 100%"
                    class="table-data"
                    row-class-name="row-class"
                    cell-class-name="cell-class"
                    header-row-class-name="header-row-class"
                    header-cell-class-name="header-cell-class"
                  >
                    <el-table-column prop="chun" align="center" label=" 夏">
                    </el-table-column>
                    <el-table-column prop="qiu" align="center" label=" 秋">
                      <template slot-scope="scope">
                            <div>{{scope.row.qiu}}12323</div>
                          </template>
                    </el-table-column>
                    <el-table-column prop="chun" align="center" label=" 春">
                    </el-table-column>
                  </el-table>
                </template>
              </el-table-column>
              <el-table-column prop="dyxn" align="center" label=" 第三学年">
                <template slot-scope="scope">
                  <el-table
                    :data="tableData2"
                    border
                    style="width: 100%"
                    class="table-data"
                    row-class-name="row-class"
                    cell-class-name="cell-class"
                    header-row-class-name="header-row-class"
                    header-cell-class-name="header-cell-class"
                  >
                    <el-table-column prop="xia" align="center" label=" 夏">
                    </el-table-column>
                    <el-table-column prop="qiu" align="center" label=" 秋">
                      <template slot-scope="scope">
                            <div>{{scope.row.qiu}}12323</div>
                          </template>
                    </el-table-column>
                    <el-table-column prop="chun" align="center" label=" 春">
                    </el-table-column>
                  </el-table>
                </template>
              </el-table-column>
              <el-table-column prop="dyxn" align="center" label=" 第四学年">
                <template slot-scope="scope">
                  <el-table
                    :data="tableData2"
                    border
                    style="width: 100%"
                    class="table-data"
                    row-class-name="row-class"
                    cell-class-name="cell-class"
                    header-row-class-name="header-row-class"
                    header-cell-class-name="header-cell-class"
                  >
                    <el-table-column prop="xia" align="center" label=" 夏">
                    </el-table-column>
                    <el-table-column prop="qiu" align="center" label=" 秋">
                      <template slot-scope="scope">
                            <div>{{scope.row.qiu}}12323</div>
                          </template>
                    </el-table-column>
                    <el-table-column prop="chun" align="center" label=" 春">
                    </el-table-column>
                  </el-table>
                </template>
              </el-table-column>
            </el-table> -->
          </div>
        </div>
      </template>
    </div>

    <div class="button-group">
      <div class="" @click="cancel()">取 消</div>
    </div>
  </div>
</template>

<script>
import { termView,querycoursetypefu,setCourse } from "@/api/propositionReview/approval";
export default {
  data() {
    return {
      xuefen:'',
      xxxuefen:'',
      edxf:'',
      edxs:'',
      setTreedata: [],
      yearTable:[],//学年表格
      tableData: [],
      defaultProps: {
        children: "children",
        label: "name",
      },
      activeName: "",
      syzy: "",
      kcfl: "",
      showYprDialog: false,
      fileName: "",
      initList:{},
      tablelist: {
        mc: "",
        bb: "",
        syzy: "",
        kcfl: "",
        cc: "",
        fj: "",
        pyfafl: "",
        edzxf: "",
        bxkedxf: "",
        xxkedxf: "",
        zxkedxf: "",
        jzkedxf: "",
        sjjxkedxf: "",
        jyxledxf: "",
        sm: "",
      },
      courseTypeVOList:[],
      syzyList: [
        {
          value: "123",
          label: "123",
        },
      ],
      kcflList: [
        {
          value: "分类一",
          label: "分类一",
        },
      ],
      spanArr:[],
      pos:0,
    };
  },
  mounted() {
    this.initData();
    this.getSpanArr()
    // this.getCreateDId(this.tablelist)
  },
  methods: {
    getSpanArr() {
      let id = localStorage.getItem("detaisPyfaid");
      let data = [];
      setCourse(id).then(res=>{
        if(res.data.code == 200){
          data = res.data.data.classHours;
          for (var i = 0; i < data.length; i++) {
            if (i === 0) {
              this.spanArr.push(1);
              this.pos = 0;
            } else {
              if (data[i].year === data[i - 1].year) {
                this.spanArr[this.pos] += 1;
                this.spanArr.push(0);
              } else {
                this.spanArr.push(1);
                this.pos = i;
              }
            }
          }
        }
      })
    },
    objectSpanMethod({ row, column, rowIndex, columnIndex }) {
      if (columnIndex === 0) {
        if (rowIndex % this.yearTable.length === 0) {
          return {
            rowspan: this.yearTable.length,
            colspan: 1,
          };
        } else {
          return {
            rowspan: 0,
            colspan: 0,
          };
        }
      }
      if (columnIndex === 1) {
        const _row = this.spanArr[rowIndex];
        const _col = _row > 0 ? 1 : 0;
        return {
          rowspan: _row,
          colspan: _col,
        };
      }
    },
    //循环接口数据（根据点击子级id）
    forTableData(id,res){
      res.forEach(item=>{
        if(item.id == id){
          let arrXx = [];
          let arrBx = [];
          this.tableData = [];
          this.tableData = item.trainingProgramCourses;
          if(this.tableData.length > 0){
            this.tableData.forEach(item=>{
              this.edxf = item.edxf;
              this.edxs = item.edxs;
              if(item.xxlx == '选修'){
                arrXx.push(item.xuefen);
                this.xxxuefen = eval(arrXx.join('+'));
              } else if (item.xxlx == '必修'){
                arrBx.push(item.xuefen);
                this.xuefen = eval(arrBx.join('+'));
              }
            })
          } else {
            this.edxf = this.edxs = this.xuefen = this.xxxuefen = '';
          }
        } else {
          this.forTableData(id,item.childCategory)
        }
      })
    },
    //点击子级节点事件
    handleNodeClick(event){
      let arrXx = [];
      let arrBx = [];
      this.courseTypeVOList.forEach(item=>{
        if(item.id == event.id){
          this.tableData = [];
          this.tableData = item.trainingProgramCourses;
          if(this.tableData.length > 0){
            this.tableData.forEach(item=>{
              this.edxf = item.edxf;
              this.edxs = item.edxs;
              if(item.xxlx == '选修'){
                arrXx.push(item.xuefen);
                this.xxxuefen = eval(arrXx.join('+'));
              } else if (item.xxlx == '必修'){
                arrBx.push(item.xuefen);
                this.xuefen = eval(arrBx.join('+'));
              }
            })
          } else {
            this.edxf = this.edxs = this.xuefen = this.xxxuefen = '';
          }
        }else {
           this.forTableData(event.id,item.childCategory)
        }
      })
    },
    initData(){
      let that = this;
      let arrXx = [];
      let arrBx = [];
      let id = localStorage.getItem("detaisPyfaid");
      setCourse(id).then(res=>{
        const data = this.courseTypeVOList = res.data.data.courseTypeVOList;
        that.yearTable = res.data.data.classHours.length > 0 ? res.data.data.classHours : []; 
        that.initList = res.data.data;
        that.initList.fj = that.initList.fj.split(';')[1];
        console.log(data)
        this.$nextTick(() => {
       		this.$refs.treeData.setCurrentKey(data[0].id);
        });
        data.forEach(k => {
          that.setTreedata.push({
            id: k.id,
            name: k.flmc,
            disabled: true,
            children: this.getListChild(k.childCategory),
          });
          this.tableData = [];
          this.tableData = data[0].trainingProgramCourses;
          if(data[0].trainingProgramCourses.length > 0){
            data[0].trainingProgramCourses.forEach(item=>{
              this.edxf = item.edxf;
              this.edxs = item.edxs;
              if(item.xxlx == '选修'){
                arrXx.push(item.xuefen);
                this.xxxuefen = eval(arrXx.join('+'));
              } else if (item.xxlx == '必修'){
                arrBx.push(item.xuefen);
                this.xuefen = eval(arrBx.join('+'));
              }
            })
          } else {
            this.edxf = this.edxs = this.xuefen = this.xxxuefen = '';
          }
        })
      })
    },
    //获取树形子级节点
    getListChild(data) {
      let tree =[];
      if(data.length){
        data.forEach(k => {
          tree.push({
            id: k.id,
            name: k.flmc,
            children:this.getListChild(k.childCategory)
          })
        })
      }
      return tree
    },
    cancel(){
      let pagebs = localStorage.getItem("detaisPages");
      if(pagebs == 'trainSearch'){
        this.$router.push({
          path: "/captain/training/trainSearch", //要跳转的页面的路由
        });
        localStorage.removeItem("detaisPyfaid");
      } else {
        this.$router.push({
          path: "/admin/training/implementation", //要跳转的页面的路由
        });
      }
    }
  },
};
</script>
<style lang="less" scoped>
@import "../../../styles/delayedExam.less";
.el-tree{
  position: relative;
  cursor: default;
  background: #FFF;
  font-weight: 600;
}
.middInfo {
  margin-right: 200px;
}
// /deep/.el-table th, .el-table tr{
//   background-color: #4D81C0 !important;
// }
/deep/.el-table th,
.el-table tr {
  color: #004ca7;
}
.table-data {
  width: 100%;
  border: 0.8px solid #004ca7;
  border-radius: 9px;
  font-size: 14px;
  font-family: Microsoft YaHei;
  font-weight: 400;
  color: #004ca7;
}
/deep/.el-tabs {
  width: 95%;
  margin: 0 auto;
}
/deep/.el-input__inner {
  border: none;
}
.bk {
  /deep/ .el-input__inner {
    border-radius: 4px;
    border: 1px solid #004ca7;
  }
}
.zyjs {
  width: 30% !important;
  margin-left: 40px !important;
  /deep/ .el-input__inner {
    height: 70px !important;
    border-radius: 4px;
    border: 1px solid #004ca7;
  }
}
.el-input {
  width: 26%;
  display: flex;
  align-items: center;
  margin-left: 40px;
}
.my-form-item {
  height: 80px;
}
.el-date-editor {
  width: 38%;
}
.choose-ypr-container {
  width: 100%;
  margin: 0px auto;

  .choose-ypr-search-container {
    .el-input--prefix .el-input__inner {
      padding-left: 30px;
    }

    .el-input__inner {
      &::placeholder {
        color: #b8b8b8;
      }

      &::-webkit-input-placeholder {
        /* WebKit browsers 适配谷歌 */
        color: #b8b8b8;
      }

      &:-moz-placeholder {
        /* Mozilla Firefox 4 to 18 适配火狐 */
        color: #b8b8b8;
      }

      &::-moz-placeholder {
        /* Mozilla Firefox 19+ 适配火狐 */
        color: #b8b8b8;
      }

      &:-ms-input-placeholder {
        /* Internet Explorer 10+  适配ie*/
        color: #b8b8b8;
      }
    }

    display: flex;
    flex-direction: row;
    align-items: center;

    .title {
      font-size: 18px;
      font-family: Microsoft YaHei;
      font-weight: bold;
      line-height: 20px;
      color: #004ca7;
      margin-right: 5px;
    }

    .search-button {
      width: 77px;
      height: 28px;
      line-height: 28px;
      background: #f1f8fe;
      border: 1px solid #51aef6;
      border-radius: 6px;
      cursor: pointer;
      display: flex;
      flex-direction: row;
      align-items: center;
      justify-content: center;

      > span {
        font-size: 16px;
        font-family: Microsoft YaHei;
        font-weight: 400;
        color: #51aef6;
      }

      > img {
        width: 20px;
        height: 20px;
        margin-right: 4px;
      }
    }

    .button-list {
      display: flex;
      flex-direction: row;
      align-items: center;
      margin-left: 21px;

      .button-item {
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: center;
        position: relative;
        width: 69px;
        height: 27px;
        line-height: 27px;
        border: 1px solid #004ca7;
        border-radius: 4px;
        margin-right: 10px;
        text-align: center;
        font-size: 14px;
        font-family: Microsoft YaHei;
        font-weight: 400;
        color: #004ca7;

        .del-icon {
          position: absolute;
          right: 0px;
          top: 0px;
          width: 12px;
          height: 12px;
          padding: 2px;
        }
      }
    }
  }

  .choose-ypr-container .choose-ypr-table-container .el-table__header th {
    padding: 0;
    height: 57px;
    background-color: #edf2f9;
    font-size: 16px;
    font-family: Microsoft YaHei;
    font-weight: bold;
    line-height: 20px;
    color: #004ca7;
  }

  /deep/ .el-table .cell {
    color: #004ca7;
  }

  .choose-ypr-table-container {
    margin-top: 30px;

    .el-table td,
    .el-table th.is-leaf,
    .el-table--border,
    .el-table--group {
      border-color: #c7d7eb;
    }

    .el-table__header tr,
    .el-table__header th {
      padding: 0;
      height: 57px;
      background-color: #edf2f9;
      font-size: 16px;
      font-family: Microsoft YaHei;
      font-weight: bold;
      line-height: 20px;
      color: #004ca7;
    }

    .el-table__body tr,
    .el-table__body td {
      padding: 0;
      height: 51px;
    }

    .table-data {
      width: 100%;
      border: 0.8px solid #004ca7;
      border-radius: 9px;
      font-size: 14px;
      font-family: Microsoft YaHei;
      font-weight: 400;
      color: #004ca7;
    }
  }
}

.assessment-container {
  .el-dialog__body {
    height: 251px;
  }

  .el-dialog__footer {
    padding: 10px 20px 45px;
  }

  .el-checkbox__inner:hover {
    border-color: #004ca7;
  }

  .el-checkbox__inner {
    border: 1px solid #004ca7;
    border-radius: 0;
    height: 18px;
    width: 18px;
  }

  .el-checkbox__inner::after {
    height: 10px;
    left: 6px;
  }

  .el-checkbox__input.is-checked .el-checkbox__inner,
  .el-checkbox__input.is-indeterminate .el-checkbox__inner {
    background-color: #004ca7;
    border-color: #004ca7;
  }

  .el-checkbox__input.is-checked + .el-checkbox__label {
    color: #004ca7;
  }

  .el-checkbox.is-bordered.is-checked {
    border-color: #004ca7;
  }

  .el-checkbox__input.is-focus .el-checkbox__inner {
    border-color: #004ca7;
  }
}

.cz-save {
  box-sizing: border-box;
  line-height: 44px;
  border-radius: 4px;
  font-size: 12px;
  font-family: Microsoft YaHei;
  font-weight: 400;
  text-align: center;
  margin-top: 70px;
  margin-left: 40px;
  display: flex;
  flex-direction: row;
  cursor: pointer;
  align-content: center;
  justify-content: center;
  align-items: center;
}

.jf-save {
  display: flex;
  align-items: center;
  margin-left: 48px;
}

.fileClass {
  position: relative;
  cursor: pointer;

  .save {
    width: 120px;
    height: 50px;
    position: absolute;
    top: 0;
    left: 0;
    opacity: 0;
    color: #fff;
    background: #303133;
  }
}

.my-form-item-value {
  font-size: 16px;
  color: #004ca7;
  height: 100%;
  flex: 1;
  line-height: 60px;
  padding-left: 38px;
  display: flex;
  align-items: center;
}

.assessment-edit-plan-container {
  .assessment-design {
    .el-textarea__inner {
      resize: none;
      font-size: 16px;
      color: rgba(0, 76, 167, 1);
    }
  }
}
.my-border-container {
  width: 100%;
  height: 100%;
  border: 1px solid #004ca7;
  border-radius: 5px;
}
</style>
<style scoped lang="less">
.assessment-edit-plan-container {
  .assessment-design {
    padding: 25px 38px !important;
  }

  .button-group {
    margin-top: 50px;
    text-align: center;

    > div {
      display: inline-block;
      font-size: 18px;
      padding: 6px 22px;
      border-radius: 6px;

      &:nth-child(1) {
        color: #ff3819;
        border: 1px solid #ff3819;
        background: #ffefef;
      }
    }
  }
}
</style>
